package com.app.studyroom.mapper;

import java.util.*;

public class ClassroomInfoMapper {
    // 映射：ID -> 名称
    private static final Map<String, String> idToNameMap = new HashMap<>();
    // 映射：ID -> 地址
    private static final Map<String, String> idToAddressMap = new HashMap<>();
    // 映射：教室ID -> 所属区域ID
    private static final Map<String, String> classroomToAreaMap = new HashMap<>();

    // 区域ID列表（cidNum == 1）
    private static final List<String> areaIdList = new ArrayList<>();
    // 教室ID列表（cidNum == 2）
    private static final List<String> classroomIdList = new ArrayList<>();

    /** 添加任意ID的信息（区域或教室） */
    public static void put(String id, String name, String address) {
        idToNameMap.put(id, name);
        idToAddressMap.put(id, address);
    }

    /** 添加区域ID */
    public static void addAreaId(String id) {
        areaIdList.add(id);
    }

    /** 添加教室ID，并记录其所属区域ID */
    public static void addClassroomId(String classroomId, String parentAreaId) {
        classroomIdList.add(classroomId);
        classroomToAreaMap.put(classroomId, parentAreaId);
    }

    /** 获取任意ID的名称 */
    public static String getName(String id) {
        return idToNameMap.getOrDefault(id, "未知教室");
    }

    /** 获取任意ID的地址 */
    public static String getAddress(String id) {
        return idToAddressMap.getOrDefault(id, "未知地址");
    }

    /** 获取所有区域ID */
    public static List<String> getAreaIdList() {
        return areaIdList;
    }

    /** 获取所有教室ID */
    public static List<String> getClassroomIdList() {
        return classroomIdList;
    }

    /** 获取某个教室的所属区域ID */
    public static String getParentAreaId(String classroomId) {
        return classroomToAreaMap.get(classroomId);
    }

    /** 清空所有缓存 */
    public static void clear() {
        idToNameMap.clear();
        idToAddressMap.clear();
        areaIdList.clear();
        classroomIdList.clear();
        classroomToAreaMap.clear();
    }
}
